import { CustomTableInterface } from '@/components/ProTable/interface';
import { PublicInterface } from '@/interface/public';
import { useFinancialInfoForm } from '../form/use-financialInfoForm';

/**
 * 财务信息
 */

export function useFinancialInfoData(proTableBox: PublicInterface.ProTableValue, drawerObj: any) {
  const getFinancialInfoData = () => {
    financeInfoList(financialInfoData.initParam).then((data: any) => {
      financialInfoData.data = data || {};
    });
  };

  const { openFinancialInfoForm, financialInfoForm, saveAddFinancialInfoForm } = useFinancialInfoForm(getFinancialInfoData);

  let financialInfoData = reactive<CustomTableInterface>({
    initParam: {
      rosterId: ''
    },
    data: [],
    // 表格配置项
    columns: [
      {
        label: '开户行',
        prop: 'bankName'
      },
      {
        label: '银行卡号',
        prop: 'bankNumber'
      },

      {
        label: '社保编号',
        prop: 'socialSecurityNumber'
      },

      {
        label: '商保编号',
        prop: 'commercialInsurance'
      },

      {
        label: '公积金账号',
        prop: 'accumulationFund'
      },
      {
        prop: 'remark',
        label: '备注'
      }
    ],
    headButtonList: [],
    rowButtonList: [
      {
        label: 'edit',
        type: 'primary',
        icon: 'svg-edit',
        attrs: {
          plain: true
        },
        // permissionCode: 'roster:saveFin',
        methods: () => {
          const params = {
            ...financialInfoData.data,
            rosterId: drawerObj.value.id
          };
          openFinancialInfoForm('编辑财务信息', params);
        }
      }
    ]
  });

  return { financialInfoData, financialInfoForm, saveAddFinancialInfoForm, getFinancialInfoData };
}
